//
//  SLIdentificationTooltip.swift
//  sulit-loan
//
//  Created by 王刚锋 on 2025/4/20.
//  Copyright © 2025 coolBoy. All rights reserved.
//

import UIKit

class SLIdentificationTooltip: UIViewController {
    var handle:SLBlock?
    var type:AlertType = .card
    enum AlertType {
        case card
        case face

    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = rgba(hex: "#000000", a: 0.7)
        self.titleL.isHidden = false
        self.detailL.isHidden = false
        
        if self.type == .card {
            self.cardBig.isHidden = false
            self.confirmButton.isHidden = false
            self.closeBtn.isHidden = false
        }else if self.type == .face{
            self.faceA.isHidden = false
            self.faceB.isHidden = false
            self.confirmButton.isHidden = false
            self.closeBtn.isHidden = false
        }
    }
    class func showAlert(page:UIViewController,type:AlertType,handle:SLBlock?){
        let alert = SLIdentificationTooltip()
        alert.type = type
        alert.handle = handle
        alert.modalPresentationStyle = .overCurrentContext
        alert.modalTransitionStyle = .crossDissolve
        page.present(alert, animated: true)
    }

    lazy var backgroundView:UIView = {
        let pt = create_view(bgColor: .white, supView: self.view) { make in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.height.equalTo(516)
            make.bottom.equalTo(0)
        }
        pt.layer.masksToBounds = true
        pt.layer.cornerRadius = 12
        return pt
    }()
    lazy var reddot:UIImageView = {
        let pt = create_imageView(image: IMAGE("icon-warn"), mode: .scaleAspectFill, supView: self.backgroundView) { make in
            make.top.equalTo(65)
            make.left.equalTo(25)
            make.width.height.equalTo(25)
        }
        return pt
    }()
    lazy var titleL:UILabel = {
        let pt = create_label(text: "Demonstration", textColor: .black,textFont: SLFontConfig.medium18,alignment:.center, supView: self.backgroundView) { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(24)
        }
        pt.numberOfLines = 0
        return pt
    }()
    lazy var detailL:UILabel = {
        let pt = create_label(text: "Please submit certification according to the example to avoid blurring, obstruction, and reflection.", textColor: rgba(hex: "#FF461B"),textFont: SLFontConfig.regular12,alignment: .left, supView: self.backgroundView) { make in
            make.left.equalTo(self.reddot.snp.right).offset(5)
            make.top.equalTo(63)
            make.right.equalTo(-25)
        }
        pt.numberOfLines = 0
        return pt
    }()

    lazy var closeBtn:UIButton = {
        let pt = create_button(image: IMAGE("icon_return"), supView: self.backgroundView, closure: { make in
            make.top.equalTo(25)
            make.left.equalTo(15)
            make.height.width.equalTo(24)
        }, selector: (target: self, action: #selector(buttonClick), event:.touchUpInside))

        return pt
    }()
    
    lazy var confirmButton:UIButton = {
        let pt = create_button(title: "Confirm", titleColor: .white,titleFont: SLFontConfig.medium16,bgColor: rgba(hex: "#1608EC"), image: nil, supView: self.view, closure: { make in
            make.bottom.equalTo(-48)
            make.left.equalTo(47)
            make.right.equalTo(-47)

            make.height.equalTo(44)
        }, selector: (target: self, action: #selector(buttonClick), event:.touchUpInside))
        pt.layer.cornerRadius = 22
        
        return pt
    }()
    
    private lazy var cardBig:UIImageView = {
        let v = create_imageView(image: IMAGE("cardbig"), mode: .scaleToFill, supView: self.backgroundView) { make in
            make.width.equalTo(299)
            make.height.equalTo(256)
            make.centerX.equalToSuperview()
            make.top.equalTo(127)
        }
        v.isHidden = true
        return v
    }()
    
    private lazy var faceA:UIImageView = {
        let v = create_imageView(image: IMAGE("face_pop_sample_right"), mode: .scaleToFill, supView: self.backgroundView) { make in
            make.width.equalTo(178)
            make.height.equalTo(146)
            make.centerX.equalToSuperview()
            make.top.equalTo(135)
        }
        v.isHidden = true
        return v
    }()
    private lazy var faceB:UIImageView = {
        let v = create_imageView(image: IMAGE("face_pop_sample_wrong"), mode: .scaleToFill, supView: self.backgroundView) { make in
            make.width.equalTo(315)
            make.height.equalTo(77)
            make.centerX.equalToSuperview()
            make.top.equalTo(self.faceA.snp.bottom).offset(26)
        }
        v.isHidden = true
        return v
    }()
    
    
    @objc func buttonClick(btn: UIButton){
        
        self.dismiss(animated: true)
        if btn == self.closeBtn {
            return
        }
        if let block = self.handle{
            block(0)
        }
    }
}


